﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Data;

namespace PeisongWeb.admin
{
    public partial class categoryList : adminPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                
                if (hasPermission("BB", 1))
                {
                    drpBind();
                    rptBind();
                }
                else
                {
                    Library.Script.ClientMsgUrl("没有权限！", "index.aspx");
                    return;
                }
            }
        }
        private void drpBind()
        {
            drp_parentType.DataSource = logic.category.select("treelevel=0", "categoryId", 1000, 1).Tables[1];
            drp_parentType.DataBind();
            drp_parentType.Items.Insert(0, new ListItem("--请选择--", ""));
        }
        void rptBind()
        {
            StringBuilder where = new StringBuilder();
            where.Append("treelevel=1");
            if (drp_parentType.SelectedValue.Trim() != "")
                where.AppendFormat("and parentId = {0}", Convert.ToInt32(drp_parentType.SelectedValue));
            if (txt_shortName.Text.Trim() != "")
                where.AppendFormat("and shortname ='{0}'", txt_shortName.Text.Trim());
            if (txt_categoryName.Text.Trim() != "")
                where.AppendFormat("and name like '%{0}%'",txt_categoryName.Text.Trim());
            DataSet ds = logic.category.subList(where.ToString(), "categoryId", AspNetPager1.PageSize, AspNetPager1.CurrentPageIndex);
            AspNetPager1.RecordCount = Convert.ToInt32(ds.Tables[0].Rows[0][0]);
            rpt_list.DataSource = ds.Tables[1];
            rpt_list.DataBind();
        }
        protected void rpt_list_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "Del")
            {
                int categoryId = Convert.ToInt32(e.CommandArgument);
                string infor;
                logic.category.delete(categoryId);
                rptBind();
                infor = "删除成功！";
                Library.Script.ClientMsg(infor);
            }
        }
        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            rptBind();
        }
        protected void lbtn_Search_Click(object sender, EventArgs e)
        {
            rptBind();
        }
    }
}
